#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
class Solution1 {
public:
    vector<vector<int>> threeSum(vector<int>& nums)
    {
        vector<vector<int>> vv;
        sort(nums.begin(), nums.end());
        for (int i = 0;i < nums.size();++i)
        {
            while (i && nums[i] == nums[i - 1])
            {
                ++i;
                if (i >= nums.size())
                    break;
            }
               
            int left = i + 1, right = nums.size() - 1;
            while (left < right)
            {
                if (nums[left] + nums[right] + nums[i] == 0)
                {
                    vv.push_back({ nums[i],nums[left],nums[right] });
                    ++left;
                    --right;
                    while (left < right && nums[left] == nums[left - 1])
                        ++left;
                    while (left < right && nums[right] == nums[right + 1])
                        --right;
                }
                else if (nums[left] + nums[right] + nums[i] < 0)
                {
                    left++;
                }
                else
                {
                    right--;
                }
            }
        }
        return vv;
    }
};
class Solution2
{
public:
    int minSubArrayLen(int target, vector<int>& nums)
    {
        int len = 0;
        int left = 0, right = 0;
        int sum = nums[0];
        int n = nums.size();
        while (right < n)
        {
            if (sum < target)
            {
                ++right;
                if (right < n)
                {
                    sum += nums[right];
                }
            }
            else if (sum >= target)
            {
                sum -= nums[left];
                ++left;
            }
            if (sum >= target)
            {
                if (len == 0 || right - left + 1 < len)
                    len = right - left + 1;
            }
        }
        return len;
    }
};
class Solution
{
public:
    bool IsRepeat(int hash[], int n)
    {
        for (int i = 0;i < n;++i)
        {
            if (hash[i] == 2)
                return true;
        }
        return false;
    }
    int lengthOfLongestSubstring(string s)
    {
        if (s.empty())
            return 0;
        int hash[128] = { 0 };
        int left = 0, right = 0, len = 1, n = s.size();
        hash[s[right]] = 1;
        while (right < n)
        {
            if (right ==  4)
            {
                int a=0;
            }
            ++right;
            if (right >= n)
                break;
            ++hash[s[right]];
            while (IsRepeat(hash, 128))
            {
                --hash[s[left]];
                ++left;
            }
            len = max(len, right - left + 1);
        }
        return len;
    }
};
int main()
{
    vector<int> v= { 2,3,1,2,4,3 };
    string str = "bbbbb";
    //Solution().minSubArrayLen(7, v);
    Solution().lengthOfLongestSubstring(str);
    int a = 0;
	return 0;
}